package com.lcredu.springboot.furn.util;

/**
 * @author 黎长容
 * @date 2025-08-19 17:57
 */
//1.返回的信息类
//2. 
public class Result<T> {
    //状态码
    private String code;
    //信息
    private String msg;
    //数据
    private T data;

    //无参构造

    public Result() {
    }

    //有参构造
    public Result(T data) {
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    //1. 返回成功的方法--无参数
    public static Result success() {
        Result result = new Result();
        result.setCode("200");
        result.setMsg("success");
        return result;
    }

    //2. 返回成功的方法--有参数
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>(data);
        result.setCode("200");
        result.setMsg("success");
        return result;
    }

    //3. 返回失败的方法--无参数
    public static Result error(String code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    //4. 返回失败的方法--有参数
    public static <T> Result error(String code, String msg, T data) {
        Result<T> result = new Result<>(data);
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
